/*
 * @Author: xiguan
 * @Email: xiguan.teng@qq.com
 * @Version: 1.0
 * @Date: 2022-09-21 10:38:11
 * @LastEditTime: 2022-09-21 14:37:15
 */
#include <bits/stdc++.h>
#include <stdlib.h>

using namespace std;
typedef long long ll;

void infect( vector<vector<int>> &m, int idx, int jdx, int N, int M ){
    if( idx < 0 || jdx < 0 || idx > N || jdx > M || m[idx][jdx] != 1 ){
        return ;
    }
    m[idx][jdx] = 2;
    infect( m, idx + 1, jdx, N, M );
    infect( m, idx - 1, jdx, N, M );
    infect( m, idx, jdx + 1, N, M );
    infect( m, idx, jdx - 1, N, M );
}

int countIslands( vector<vector<int>> &m ){
    if( m.size() == 0 || m[0].size() == 0 ){
        return 0;
    }

    int N = m.size(), M = m[0].size();
    int ans = 0;

    for( int idx = 0; idx < N; ++ idx ){
        for( int jdx = 0; jdx < M; ++ jdx ){
            if( m[idx][jdx] == 1 ){
                ans ++;
                infect( m, idx, jdx, N, M );
            }
        }
    }
    return ans;
}

int main( int argc, char *argv[] ){

    

    return 0;
}